#include<bits/stdc++.h>
using namespace std;
/*
10
8 19 20 30 40 10 20 30 30 20
3
3 40 10 20
4 8 19 20 30
3 30 30 20
*/
int main() {
	int n;
	cin >> n;
	string result = "";
	while (n--) {
		int t;
		cin >> t;
		result += to_string(t);
	}
	vector<string> vec;
	int k;
	cin >> k;
	while (k--) {
		int v;
		cin >> v;
		string res = "";
		while (v--) {
			int t;
			cin >> t;
			res += to_string(t);
		}
		vec.push_back(res);
	}
	for (int i = 0; i < vec.size(); i++) {
		result.replace(result.find(vec[i]), vec[i].length(), to_string(i + 1));
	}
	for (int i = 0; i < result.length(); i++) {
		if (i < result.length() - 1) cout << result[i] << " ";
		else cout << result[i];
	}

	return 0;
}